# 第一种写法
# file = open(r'a.txt', 'w', encoding='utf-8')
# file.write('我爱你world,我爱你')
# file.close()

# 第二种写法
file = open(r'a.txt', 'r', encoding='utf-8')
txt = file.read()
newtxt = txt.replace('python', 'world')
file.close()
file1 = open(r'a.txt', 'w', encoding='utf-8')
file1.write(newtxt)
file1.close()

print(txt)
